package cn.wolfcode.wechat.controller;

import cn.wolfcode.wechat.domain.LocationBlacklist;
import cn.wolfcode.wechat.query.LocationBlacklistQueryObject;
import cn.wolfcode.wechat.service.ILocationBlacklistService;
import cn.wolfcode.wechat.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class LocationBlacklistController {
    @Autowired
    private ILocationBlacklistService locationBlacklistService;

    @RequestMapping("locationBlacklist")
    public String locationBlacklist(Model model, @ModelAttribute("qo") LocationBlacklistQueryObject qo){
        List<LocationBlacklist> list = locationBlacklistService.getAll(qo);
        model.addAttribute("list",list);
        return "location_blacklist";
    }

    @RequestMapping("locationBlacklistUpdate")
    @ResponseBody
    public JSONResult locationBlacklistUpdate(LocationBlacklist locationBlacklist){
        try {
            locationBlacklistService.saveOrUpdate(locationBlacklist);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false, e.getMessage());
        }
    }

    @RequestMapping("locationBlacklistDelete")
    @ResponseBody
    public JSONResult locationBlacklistDelete(Long id){
        try {
            locationBlacklistService.delete(id);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false, e.getMessage());
        }
    }
}
